package app

import (
	midd "a-admin/web/middleware"

	"github.com/gofiber/fiber/v2"
)

const bastApi = "/app"

func InitAppRoutes(r fiber.Router) {
	// APP 接口
	apiServer := NewAppApiController()
	r.Post(bastApi+"/login", apiServer.Login)
	r.Get(bastApi+"/captchaImage", apiServer.CaptchaImage)
	r.Post(bastApi+"/logout/:tk", apiServer.LoginOut)
	r.Get(bastApi+"/captchaVerify", apiServer.CaptchaVerify)
	r.Get(bastApi+"/getEmailCode", apiServer.GetEmailCode)
	r.Get(bastApi+"/emailCodeVerify", apiServer.EmailCodeVerify)
	r.Post(bastApi+"/register", apiServer.Register)
	r.Get(bastApi+"/getInfo", apiServer.GetInfo)

	// 用户接口
	userServer := NewAppUserController()
	r.Get(bastApi+"/user/rows", midd.PermsHandler("app:user:list"), userServer.List)
	r.Get(bastApi+"/user/get/:id", midd.PermsHandler("app:user:query"), userServer.Get)
	r.Post(bastApi+"/user/del/:ids", midd.PermsHandler("app:user:remove"), midd.OperLogHandler("APP", midd.DELETE), userServer.Del)
	r.Post(bastApi+"/user/add", midd.PermsHandler("app:user:add"), midd.OperLogHandler("APP", midd.UPDATE), userServer.Add)
	r.Post(bastApi+"/user/edit", midd.PermsHandler("app:user:edit"), midd.OperLogHandler("APP", midd.UPDATE), userServer.Edit)
	r.Post(bastApi+"/user/export", midd.PermsHandler("app:user:export"), midd.OperLogHandler("APP", midd.EXPORT), userServer.Export)

	r.Get(bastApi+"/user/getSelectList", userServer.GetSelectList)
	r.Post(bastApi+"/user/importTemplate", userServer.ImportTemplate)
	r.Post(bastApi+"/user/importData", midd.PermsHandler("app:user:import"), midd.OperLogHandler("APP", midd.IMPORT), userServer.ImportData)
	r.Post(bastApi+"/user/changeStatus", midd.PermsHandler("app:user:edit"), midd.OperLogHandler("APP", midd.UPDATE), userServer.ChangeStatus)
	r.Post(bastApi+"/user/resetPwd", midd.PermsHandler("app:user:edit"), midd.OperLogHandler("APP", midd.UPDATE), userServer.ResetPwd)

	r.Get(bastApi+"/user/profile/get", userServer.Profile)
	r.Post(bastApi+"/user/profile/edit", midd.OperLogHandler("APP", midd.UPDATE), userServer.Edit)
	r.Post(bastApi+"/user/profile/updatePwd", midd.OperLogHandler("个人信息", midd.UPDATE), userServer.UpdatePwd)
	r.Get(bastApi+"/user/profile/avatar/*", userServer.GetAvatar)
	r.Post(bastApi+"/user/profile/avatar", userServer.Avatar)

	// 余额接口
	balanceServer := NewAppBalanceController()
	r.Get(bastApi+"/balance/rows", balanceServer.List)
	r.Get(bastApi+"/balance/get/:id", balanceServer.Get)
	r.Post(bastApi+"/balance/add", midd.OperLogHandler("APP", midd.INSERT), balanceServer.Add)
	r.Post(bastApi+"/balance/edit", midd.OperLogHandler("APP", midd.UPDATE), balanceServer.Edit)
	r.Post(bastApi+"/balance/:ids", midd.OperLogHandler("APP", midd.DELETE), balanceServer.Del)
}
